const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const MemberLevel = sequelize.define('MemberLevel', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '会员等级名称'
  },
  level: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '会员等级'
  },
  points_required: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '所需积分'
  },
  benefits: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '会员权益'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '会员等级描述'
  },
  icon: {
    type: DataTypes.STRING,
    comment: '会员等级图标'
  },
  color: {
    type: DataTypes.STRING,
    comment: '会员等级颜色'
  },
  discount_rate: {
    type: DataTypes.FLOAT,
    defaultValue: 1.0,
    comment: '折扣率'
  },
  monthly_points: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '每月积分'
  },
  special_privileges: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '特殊权益'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    defaultValue: 'active',
    comment: '会员等级状态'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  underscored: true,
  comment: '会员等级信息表'
});

module.exports = MemberLevel; 